﻿using System;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace SansaImageConverter
{
    /// <summary>
    /// XML settings
    /// </summary>
    public class XmlSettings
    {
		#region Fields (2) 

        private readonly static string LocalAppPath = Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
            Path.Combine(Application.CompanyName, Application.ProductName));
        private readonly static string SettingsFile = Path.Combine(LocalAppPath, "Settings.xml");

		#endregion Fields 

		#region Constructors (1) 

        public XmlSettings()
        {
            // Insert code here.
        }

		#endregion Constructors 

		#region Properties (6) 

        /// <summary>
        /// Gets or sets a value indicating whether [copy to player].
        /// </summary>
        /// <value><c>true</c> if [copy to player]; otherwise, <c>false</c>.</value>
        public bool CopyToPlayer { get; set; }

        /// <summary>
        /// Gets or sets export path
        /// </summary>
        /// <value>The export path.</value>
        public string ExportPath { get; set; }

        /// <summary>
        /// Gets or sets player path
        /// </summary>
        /// <value>The player path.</value>
        public string PlayerPath { get; set; }

        /// <summary>
        /// Gets or sets quality
        /// </summary>
        /// <value>The quality.</value>
        public InterpolationMode Quality { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [rotate images].
        /// </summary>
        /// <value><c>true</c> if [rotate images]; otherwise, <c>false</c>.</value>
        public bool RotateImages { get; set; }

        /// <summary>
        /// Gets or sets sizing
        /// </summary>
        /// <value>The sizing.</value>
        public int Sizing { get; set; }

		#endregion Properties 

		#region Methods (2) 

        /// <summary>
        /// Loads this instance.
        /// </summary>
        /// <returns></returns>
        public static XmlSettings Load()
        {
            try
            {
                XmlSerializer serial = new XmlSerializer(typeof(XmlSettings));
                using (FileStream fs = File.OpenRead(SettingsFile))
                {
                    return serial.Deserialize(fs) as XmlSettings;
                }
            }
            catch (IOException)
            {
                return new XmlSettings();
            }
        }

        /// <summary>
        /// Saves this instance.
        /// </summary>
        public void Save()
        {
            if (!Directory.Exists(LocalAppPath))
                Directory.CreateDirectory(LocalAppPath);

            try
            {
                XmlSerializer serial = new XmlSerializer(typeof(XmlSettings));
                using (FileStream fs = File.Create(SettingsFile))
                {
                    serial.Serialize(fs, this);
                }
            }
            catch (IOException)
            {
                
            }
        }

		#endregion Methods 
    }
}
